<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"/>
    <title>19-mixins混入</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak></div>

<script src="js/vue.js"></script>

<script>
    let base = {
        data() {
            return {
                visible: true
            }
        },
        methods: {
            toggle() {
                this.visible = !this.visible
            }
        }
    };
    //a组件
    let Acomponent = {
        template: `
          <div>
          <button type="button" @click="toggle()">显示/隐藏a组件</button>
          <div v-show="visible">我是A组件</div>
          </div>
        `,
        // data(){
        //     return {
        //         visible:true
        //     }
        // },
        // methods:{
        //    toggle(){
        //        this.visible=!this.visible;
        //    }
        // },
        mixins: [base]
    };
    //b组件
    let Bcomponent = {
        template: `
           <div>
                <button type="button" v-on:click="toggle()">显示/隐藏b组件</button>
                <div v-show="visible">我是b组件</div>
           </div>
        `,
        data() {
            return {
                visible: true //覆盖mixins里面的visible
            }
        },
        // methods:{
        //     toggle(){
        //         this.visible=!this.visible;
        //     }
        // },
        mixins: [base]
    };
    //入口组件
    let App = {
        template: `
            <div>
                <Acomponent></Acomponent>
                <Bcomponent></Bcomponent>
            </div>
        `,
        //局部组件注册方式
        components: {
            Acomponent,
            Bcomponent
        }
    };
    new Vue({
        el: "#app",
        template: `
            <App></App>
        `,
        components: {
            App
        }
    })
</script>
</body>
</html>
